package com.example.feign.clients.fallback;

import com.example.common.Entity.User;
import com.example.common.response.R;
import com.example.feign.clients.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 调用用户服务失败的服务降级类
 *
 * @author Liaorun
 */
@Slf4j
@Component
public class UserClientCallbackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable cause) {

        return new UserClient() {
            @Override
            public R<User> findById(Long id) {

                log.error("查询用户服务熔断降级，" + cause);
                return new R<User>().setMsg("查询用户服务熔断降级");
            }
        };
    }
}
